/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef HTTP2_HTTP2_STRUCT_H
#define HTTP2_HTTP2_STRUCT_H
#include <nghttp2/nghttp2.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/conf.h>
#include <string>
#include "napi/native_api.h"

struct Connection {
    SSL *ssl = nullptr;
    nghttp2_session *session = nullptr;
    int want_io;
    SSL_CTX *ssl_ctx = nullptr;
    int32_t stream_id;
    int fd;
    int data_trunck_len;
    int write_buff_len;
    int reqType; // 1 grpc
    napi_env env;
    napi_async_work asyncWork;
    napi_deferred deferred;
    napi_ref callbackRef;
    std::string host;
    std::string path;
};


struct RequestTask {
    napi_env env;
    napi_async_work asyncWork;
    napi_deferred deferred;
    napi_ref callbackRef;
    int fd = 0;
    std::string host;
    std::string path;
    std::string port;
    std::string method_;
    std::string contentType;
    int errCode;
    void *buff;
    int buffLen;
    std::string dnsText;
};

struct RequestCallback {
    napi_env env;
    napi_async_work asyncWork;
    napi_deferred deferred;
    napi_ref callbackRef;
    int type;
    void *data = nullptr;
    int error_code;
    int last_stream_id;
    int fd;
    int data_len;
    int reqType; // 1 grpc
};

struct HttpStreamErrorCallback {
    int errCode;
    const char *msg;
};

struct HandleBuffer {
    int dirty_data_Len;
    int effective_data_len;
};

#endif // HTTP2_HTTP2_STRUCT_H
